﻿<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>加载支票</title>
    <link rel="stylesheet" type="text/css" href="../Content/Css/OperaMasksUI/default/om-all.css" />
    <link rel="stylesheet" type="text/css" href="../Content/Css/list.css" />
    <script type="text/javascript" src="../Scripts/jquery.1.6.3.min.js"></script>
    <script type="text/javascript" src="../Scripts/json2.js"></script>
    <script type="text/javascript" src="../Scripts/common.js"></script>
    <script type="text/javascript" src="../Scripts/OperaMasksUI/operamasks-ui.min.js"></script>
    <script type="text/javascript" src="../Scripts/Plugin/jquery.form.js"></script>
    <script type="text/javascript" src="../Scripts/Plugin/artDialog4.1.7/jquery.artDialog.js?skin=default"></script>
    <script type="text/javascript" src="../Scripts/Plugin/artDialog4.1.7/plugins/iframeTools.js"></script>
    <script type="text/javascript" src="../Scripts/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../Scripts/locale/easyui-lang-zh_CN.js"></script>
    <link rel="stylesheet" type="text/css" href="../Scripts/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../Scripts/themes/icon.css">
    <script type="text/javascript">
        var validatorForm, submitForm, detailForm;
        var actionRoot = "../handler/ajax.ashx?type=AjaxSystem", comboxBankData = [], comboxTypeData = [];

        $(document).ready(function () {
            detailForm = $('#viewForm');
            $.ajax({
                cache: false, async: false,
                url: '../Handler/combox.ashx?view=vBaseData',
                dataType: 'json', type: 'post',
                beforeSend: function () {
                    $.omMessageBox.waiting({
                        title: '请等待',
                        content: '服务器正在加载相关基础数据信息,请稍后...'
                    });
                },
                complete: function () {
                    $.omMessageBox.waiting("close");
                },
                success: function (data) {
                    comboxBankData = [], comboxTypeData = [];
                    $.each(data, function (index, value) {
                        switch (value.Type) {
                            case '支票银行':
                                comboxBankData.push({ name: value.Name, code: value.Code, type: value.Type });
                                return true;
                            case '支票额度':
                                comboxTypeData.push({ name: value.Name, code: value.Code, type: value.Type });
                                return true;
                            default:
                                return true;
                        }
                    })
                },
                error: function (result) {
                    $.omMessageBox.alert({
                        content: '发现系统错误,请重新登录<BR>错误码：' + result.status
                    });
                }
            });
            $('#Bank', detailForm).combobox({
                data: comboxBankData,
                valueField: 'name',
                textField: 'name',
                editable: false
            });
            $('#CheckType', detailForm).combobox({
                data: comboxTypeData,
                valueField: 'code',
                textField: 'name',
                editable: false
            });
            validatorForm = $('#viewForm').validate({
                errorContainer: "#errorMessages",
                errorLabelContainer: "#errorMessages",
                wrapper: "span",
                errorClass: "omError",
                rules: {
                    From: { required: true },
                    Bank: { required: true },
                    PurchaseDate: { required: true },
                    Qty: { required: true, digits: true }
                },
                messages: {
                    From: { required: "[起始号码]不能为空" },
                    Bank: { required: "[支票银行]不能为空" },
                    PurchaseDate: { required: "[购买时间]不能为空" },
                    Qty: { required: "[数量]不能为空", digits: "[数量]必须是数字" }
                }
            });
            $('span#button-save', detailForm).omButton({
                icons: { left: '../Content/Images/List/accept.png' }, width: 80,
                onClick: function () {
                    if (validatorForm.form()) {
                        if ($("#Qty").val() > 0) {
                            detailForm.attr("action", actionRoot + "&method=AddBatchCheck");
                            submitForm(detailForm, function (data) {
                                if (data.IsError) {
                                    $.omMessageBox.alert({
                                        type: 'error',
                                        content: '错误<BR>：' + data.Message,
                                        onClose: function () {
                                            $("#From", detailForm).focus();
                                        }
                                    });
                                }
                                else {
                                    $.omMessageBox.alert({
                                        type: 'success',
                                        content: '批量新增支票成功',
                                        onClose: function () {
                                            art.dialog.close();
                                        }
                                    })
                                }
                            });
                        }
                        else {
                            $.omMessageBox.alert({
                                type: 'error',
                                content: '错误<BR>：' + data.Message,
                                onClose: function () {
                                    $("#Qty", detailForm).focus();
                                }
                            });
                        }
                    }
                }
            });
            $('span#button-cancel', detailForm).omButton({
                icons: { left: '../Content/Images/List/cross.png' }, width: 80,
                onClick: function () {
                    art.dialog.close();
                }
            });
        });

        submitForm = function (mainform, success, error) {
            if (!mainform)
                return false;
            else {
                mainform.ajaxSubmit({
                    type: "POST",
                    dataType: 'json',
                    success: success,
                    clearForm: false,
                    beforeSubmit: function (formData, jqForm, options) {
                        $(":checkbox,:radio", jqForm).each(function () {
                            if (!existInFormData(formData, this.name)) {
                                formData.push({ name: this.name, type: this.type, value: this.checked });
                            }
                        });
                        for (var i = 0, l = formData.length; i < l; i++) {
                            var o = formData[i];
                            if (o.type == "checkbox" || o.type == "radio") {
                                o.value = $("[name=" + o.name + "]", jqForm)[0].checked ? "true" : "false";
                            }
                        }
                    },
                    beforeSend: function (a, b, c) {
                        $.omMessageBox.waiting({
                            title: '正在保存数据中...',
                            content: '服务器正在处理请求......'
                        });
                    },
                    complete: function () {
                        $.omMessageBox.waiting("close")
                    },
                    error: function (result) {
                        $.omMessageBox.waiting("close")
                        $.omMessageBox.alert({
                            content: '错误 <BR>：' + result.status
                        });
                    }
                });
            }
        }

        function existInFormData(formData, name) {
            for (var i = 0, l = formData.length; i < l; i++) {
                var o = formData[i];
                if (o.name == name) return true;
            }
            return false;
        }

    </script>
</head>
<body>
        <div id="center-panel">
    <div id="detail-form">
        <form id="viewForm">
            <div id="errorMessages" class="error"></div>
            <table style="width:100%;">
                <tr>
                    <td align="right" style="width: 80px; color: red;">支票银行</td>
                    <td align="left" style="width: 120px">
                        <class="easyui-combobox" name="Bank" id="Bank" /></td>
                    <td align="center" style="width: 80px;"><span id="button-save">保存</span></td>
                </tr>
                <tr>
                    <td align="right" style="width: 80px; margin-left: 10px; color: red;">起始号码</td>
                    <td align="left" style="width: 150px">
                        <input type="text" class="input-text" name="From" id="From" maxlength="8" value="" data-options="required:false;validType:'length[1,8]'" style="border: 1px solid #A4BED4; height:20px;width: 122px;" />
                    </td>
                    <td align="center" style="width: 80px;"><span id="button-cancel">取消</span></td>
                </tr>
                <tr>
                    <td align="right" style="width: 80px; margin-left: 10px; color: red;">数&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp量</td>
                    <td align="left" style="width: 150px">
                        <input class="easyui-numberbox" name="Qty" id="Qty" style="border: 1px solid #A4BED4;height:20px;width: 122px;" data-options="precision:2,groupSeparator:','" />
                </tr>
                <tr>
                    <td align="right" style="width: 80px; color: red;">购买时间</td>
                    <td align="left" style="width: 150px">
                        <input class="easyui-datebox" name="PurchaseDate" id="PurchaseDate"  /></td>
                    <td align="right" style="width: 50px;"></td>
                </tr>
                <tr>
                    <td align="right" style="width: 80px; margin-left: 10px;">支票额度</td>
                    <td align="left" style="width: 150px">
                        <input type="text" class="input-text" name="CheckType" id="CheckType" value=""  />
                    </td>
                    <td align="right" style="width: 50px;"></td>
                </tr>
            </table>
        </form>
    </div>
            </div>
</body>
</html>
